package pt.iscte.pcd.project.local;

import java.io.File;
import pt.iscte.pcd.project.interfaces.EntryType;
import pt.iscte.pcd.project.interfaces.PCDDirectory;
import pt.iscte.pcd.project.interfaces.PCDEntry;

public abstract class LocalEntry implements PCDEntry{

	private String fullPath;
	
	private File file;

	private EntryType type;

	private PCDDirectory parent;
	
	
	@Override
	public String toString() {
		return getName();
	}
	public LocalEntry(String nome, EntryType type, PCDDirectory parent) {
		this.type = type;
		this.parent = parent;
		setFile(new File(nome));
		fullPath= nome;
		createNew();
	}
	/**
	 * Abstract method for create new entries
	 */
	public abstract void createNew();
	
	/**
	 * return the full path of an entry
	 * @return String fullPath
	 */
	public String getFullPath() {
		return fullPath;
	}
	
	/**
	 * return the parent of an entry
	 * @return PCDDirectory parent
	 */
	@Override
	public PCDDirectory getParent() {
		return parent;
	}
	

	/**
	 * return the name of an entry 
	 * @return String name
	 */
	@Override
	public String getName() {
		return getFile().getName();
	}

	/**
	 * abstract method define in localfile
	 */
	@Override
	public abstract boolean readLock();

	/**
	 * abstract method define in localfile
	 */
	@Override
	public abstract boolean writeLock() ;

	/**
	 * abstract method define in localfile
	 */
	@Override
	public abstract void readUnlock();
	
		
	

	@Override
	public abstract void writeUnlock();



	@Override
	public boolean exists() {
		return getFile().isDirectory() || getFile().isFile();
	}

	@Override
	public EntryType getType() {
		return type;
	}
	public File getFile() {
		return file;
	}
	public void setFile(File file) {
		this.file = file;
	}
	

	
	
	
}
